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

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

f = A("f")
a = B("a")
g = B("g")
n = A("n")
l = A("l")

f.r = g
a.t = n
a.z = g
g.t = l
g.z = a
n.r = a
l.r = a
assert f.r.z.z.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

f = A("f")
a = B("a")
g = B("g")
n = A("n")
l = A("l")

f.r = g
a.t = n
a.z = g
g.t = l
g.z = a
n.r = a
l.r = a
assert f.r.z.z.t.txt == "l"