class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

h = A("h")
f = B("f")
c = B("c")
k = A("k")

h.t = c
h.r = k
f.t = c
c.t = f
k.t = c
k.r = h
assert k.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

h = A("h")
f = B("f")
c = B("c")
k = A("k")

h.t = c
h.r = k
f.t = c
c.t = f
k.t = c
k.r = h
assert k.r.r.r.r.txt == "k"