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

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

f = A("f")
k = B("k")
e = A("e")
j = B("j")
h = B("h")
d = A("d")

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

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

f = A("f")
k = B("k")
e = A("e")
j = B("j")
h = B("h")
d = A("d")

f.t = j
k.r = j
e.t = j
j.r = k
h.r = j
d.t = j
assert j.r.r.r.r.r.txt == "k"