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

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

k = A("k")
a = B("a")
c = B("c")
d = A("d")
h = B("h")
b = B("b")
l = A("l")
f = A("f")
n = B("n")

k.r = d
a.t = k
c.t = d
d.r = l
h.t = l
b.t = d
l.r = d
f.r = l
n.t = d
assert b.t.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

k = A("k")
a = B("a")
c = B("c")
d = A("d")
h = B("h")
b = B("b")
l = A("l")
f = A("f")
n = B("n")

k.r = d
a.t = k
c.t = d
d.r = l
h.t = l
b.t = d
l.r = d
f.r = l
n.t = d
assert b.t.r.r.txt == "d"